<?php

namespace app\common\model;

use think\Model;
class InquiryPrice extends Model
{
    protected $resultSetType = 'collection';
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    // 追加属性
    protected $append = ['user_info'];

    public static function get_price_list($page,$inquiry_id)
    {
        $where = "inquiry_id = {$inquiry_id}";
        $order = "price DESC";
        $count = self::where($where)->count();
        $limit = 20;
        $start = ($page - 1) * $limit;
        $total = ceil($count / $limit);
        $list = self::where($where)->field("*")->order($order)->limit($start, $limit)->select();
        foreach ($list as &$value){
            $value['price'] = format_number($value['price']);
        }
        $data = [
            'total'=>$total,
            'list'=>$list
        ];
        return $data;
    }

    public function getUserInfoAttr($value,$data)
    {
        $info = User::where("user_id",$data["user_id"])->field("username,image,authen,authen_time,deposit_price")->find();
        $user_info['username'] = $info["username"];
        $user_info['user_image'] = $info["image"];
        return $user_info;
    }

    public function getAddTimeAttr($value)
    {
        if($value){
            return date("Y-m-d H:i:s");
        }else{
            return "";
        }
    }
}
